<template>
  <XtxBread>
    <XtxBreadItem to="/">首页</XtxBreadItem>
    <XtxBreadItem :to="`/category/${subObj.parentId}`">
      {{subObj.parentName}}
    </XtxBreadItem>
    <XtxBreadItem >{{subObj.name}}</XtxBreadItem>
  </XtxBread>
</template>
<script>
import { findSubCategoryFilter } from '@/api/category'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'// 传id
export default {
  name: 'SubBread',
  setup () {
    const subObj = ref({})
    const route = useRoute()
    async function getSubObj () {
      const res = await findSubCategoryFilter(route.params.id)
      console.log('面包屑', res)
      subObj.value = res.result
    }
    onMounted(() => {
      getSubObj()
    })
    // watch(
    //   () => {
    //     return route.params.id
    //   }, // 监听谁就retuan谁
    //   () => {
    //     getSubObj()
    //   } // 改变之后要做什么
    // )
    return {
      subObj
    }
  }

}
</script>
